//
//  JDApiManager.swift
//  DragonWallet
//
//  Created by volantPig on 2023/12/26.
//

import UIKit
import Moya
import SwiftyJSON

//let JDUrlBaseUrl = "http://218.60.95.39:8080"
#if DEBUG
// 测试
//let JDBaseUrl = "http://gitt.natapp1.cc/"
let JDBaseUrl = "https://dev.xiaolongbaobao.com/"//"http://218.60.95.24:8080/"

let JDImageBaseUrl = "" //"http://218.60.95.39:8080"
#else
// 测试
let JDBaseUrl = "https://dev.xiaolongbaobao.com/"//"http://218.60.95.24:8080/"
let JDImageBaseUrl = "" //"http://218.60.95.39:8080"
//// 正式
//let JDBaseUrl = "http://longpingtai.com/"
#endif

// 接口文档
// http://218.60.95.24:8080/swagger-ui/index.html

enum JDApi {
    
    // --- --- --- --- 已改 --- --- --- ---
    
    /// 查询国家代码列表
    case getCountryCodeList
    /// 获取验证码
    case getVerificationCode(_ params: [String: Any])
    /// 电话验证码登录
    case telLogin(_ params: [String: Any])
    /// 分页获取龙看板
    case bussiInfo(_ params: [String: Any])
    /// 保存龙看板
    case releaseBoard(_ params: [String: Any])
    /// 修改昵称
    case changeNickname(_ params: [String: Any])
    /// 修改手机号
    case changeMobile(_ params: [String: Any])
    /// 总注册用户数
    case getTotalRegister(_ params: [String: Any])
    /// 邀加龙商圈
    case addDragonUnion(_ params: [String: Any])
    /// 移除用户出龙商圈
    case removeDragonUnion(_ params: [String: Any])
    /// 分页获取龙商圈用户--> 龙商圈列表
    case dragonUnionList(_ params: [String: Any])
    /// 列出收货地址
    case getAddressList(_ params: [String: Any])
    /// 保存收货地址
    case saveAddress(_ params: [String: Any])
    /// 更新收货地址
    case updateAddress(_ params: [String: Any])
    /// 删除收货地址
    case deleteAddress(_ params: [String: Any])
    /// 注销账号
    case deleteAccount(_ params: [String: Any])
    /// 分页查询龙商圈圈内资讯
    case getUnionNewsList(_ params: [String: Any])
    /// 保存龙商圈圈内资讯信息
    case releaseUnionNews(_ params: [String: Any])
    /// 分页查询商务快讯
    case getBusinessNewsList(_ params: [String: Any])
    /// 列出商务快讯类型
    case getBusinessNewsType(_ params: [String: Any])
    /// 列出龙看板业务类型
    case getDragonKanbanType(_ params: [String: Any])
    /// 保存商务快讯
    case releaseBusinessNews(_ params: [String: Any])
    /// 获取龙商圈用户数量
    case getDragonUnionUserNums(_ params: [String: Any])
    /// 发布龙商圈私聊记录  -->  发送私聊信息呗
    case sendDragonUnionChatMessage(_ params: [String: Any])
    /// 购物车列表
    case getShopCartList(_ params: [String: Any])
    /// 查询商品分类
    case getGoodsType(_ params: [String: Any])
    /// 分页查询商品
    case getGoodsList(_ params: [String: Any])
    /// 分页查询订单列表
    case getOrderList(_ params: [String: Any])
    /// 查询商品详情
    case getGoodsDetail(_ params: [String: Any])
    /// 查询商品规格
    case getGoodsSpecification(_ params: [String: Any])
    /// 查询商品SKU
    case getGoodsSku(_ params: [String: Any])
    /// 上传图片
    case uploadImage(_ params: [String: Any],_ files: [UIImage],_ name: String)
    /// 上传视频
    case uploadVideo(_ params: [String: Any],_ videoPath: URL,_ name: String)
    
    /// 下载图片
    case downloadImage(_ params: [String: Any])
    /// 添加商品到购物车
    case addShopcart(_ params: [String: Any])
    /// 从购物车移除商品
    case removeGoodsFromShopcart(_ params: [String: Any])
    /// 修改购物车商品数量
    case modifyShopcartGoodsCount(_ params: [String: Any])
    /// 预保存订单
    case preSaveOrder(_ params: [String: Any])
    /// 取消订单
    case cancelOrder(_ params: [String: Any])
    /// 确认收货
    case confirmOrder(_ params: [String: Any])
    /// 查询订单详情
    case getOrderDetailInfo(_ params: [String: Any])
    
    /// 获取用户选择的商务快讯类型，包含已选中和未选中
    case listUserBusinessType
    /// 保存用户选择的商务快讯类型
    case saveUserBusinessType(_ params: [String: Any])
    /// 分页查询龙商圈私聊记录
    case privateMessageList(_ params: [String: Any])
    /// 保存订单 --> 结算
    case saveOrder(_ params: [String: Any])
    /// 分页查询我的龙商圈圈内资讯发布记录
    case getReleaseNewsRecord(_ params: [String: Any])
    /// 分页查询我的商务快讯发布记录
    case getMyBusinessNewsRecordList(_ params: [String: Any])
    /// 获取用户推荐码
    case fetchUserRecommendCode
    /// 订单支付  ---  测试用
    case doOrderPay(_ params: [String: Any])
    /// 获取用户订单数量
    case fetchOrderCount
    /// 分页查询用户推广费用列表
    case pageUserPromotionCommission(_ params: [String: Any])
    /// 获取用户账户余额
    case fetchUserBalance(_ params: [String: Any])
    /// 分页查询实名认证信息
    case pageRealNameIdentificationInfo(_ params: [String: Any])
    /// 保存实名认证信息
    case saveRealNameIdentificationInfo(_ params: [String: Any])
    /// 删除实名认证信息
    case deleteRealNameInfo(_ params: [String: Any])
    
    /// 获取微信支付参数
    case getWechatPayPayment(_ params: [String: Any])
    /// 获取微信用户信息
    case getWechatUserInfo(_ params: [String: Any])
    /// 获取支付宝支付参数infoStr
    case getAlipayPayInfoStr
    /// 用户绑定/解绑支付账户
    case bindPayAccountByUserId(_ params: [String: Any])
    ///  获取用户提现页面信息
    case getCashOutPageInfo
    /// 更新用户实名信息    （提现时  需要这个）
    case updateUserRealNameById(_ params: [String: Any])
    /// 用户提现
    case userCashOut(_ params: [String: Any])
    /// 修改头像
    case changeHeaderImg(_ params: [String: Any])
    /// 获取用户信息
    case getUserInfo
    /// 获取支付宝用户ID
    case getAlipayUserInfo(_ params: [String: Any])
    // --- --- --- --- 结束 --- --- --- ---
    
    
    
    
    
    
    
    
    
    
    /// 账号密码登录 --- 无效
    case passwordLogin(_ params: [String: Any])
    
    /// 查询看板
//    case bussiInfo(_ params: [String: Any])
    /// 龙商圈列表
    case lsqListInfo(_ params: [String: Any])
    
    
    /// 同城分享_分享包列表
    case cityShareList(_ params: [String: Any])
    
    
//    case uploadImg(_ params: [String: Any],_ files: [UIImage],_ name: String)
    
//    case uploadVideo(_ params: [String: Any],_ videoPath: URL,_ name: String)
    /// 跨境商品上传时分类
    case getcrossaddgcate(_ params: [String: Any])
    /// 跨境商城商品列表
    case goodslistcross(_ params: [String: Any])

    /// 从龙商圈中移除
    case lsqdele(_ params: [String: Any])
    
    /// 用户订单列表查询
    case userOrderList(_ params: [String: Any])
    /// 商品详情
    case goodsDetail(_ params: [String: Any])
    
    /// 龙商圏私聊信息发布
    case sendMessage(_ params: [String: Any])
    /// 立即购买 提交订单（跨境商品）
    case buyAtOnce(_ params: [String: Any])
}

extension JDApi: TargetType {
    var baseURL: URL {
        return URL.init(string: JDBaseUrl)!
    }
    
    var path: String {
        switch self {
        case .getAlipayUserInfo:
            return "api/payment/getAlipayUserInfo"
        case .getWechatUserInfo:
            return "api/payment/getWechatUserInfo"
        case .getCountryCodeList:
            return "api/goods/getCountryCodeList"
        case .getVerificationCode:
            return "api/auth/sendSmsCode"
        case .telLogin:
            return "api/auth/doLogin"
        case .bussiInfo:
            return "api/dragonKanban/pageDragonKanban"
        case .releaseBoard:
            return "api/dragonKanban/saveDragonKanban"
        case .changeNickname:
            return "api/userCenter/changeNickname"
        case .changeMobile:
            return "api/userCenter/changeMobile"
        case .getTotalRegister:
            return "api/dragonKanban/countTotalRegister"
        case .addDragonUnion:
            return "api/dragonBusinessDistrict/inviteDragonBusinessDistrict"
        case .dragonUnionList:
            return "api/dragonBusinessDistrict/pageDragonBusinessDistrictUser"
        case .getAddressList:
            return "api/address/listDeliveryAddress"
        case .saveAddress:
            return "api/address/saveDeliveryAddress"
        case .deleteAddress:
            return "api/address/deleteDeliveryAddress"
        case .deleteAccount:
            return "api/userCenter/destroyAccount"
        case .removeDragonUnion:
            return "api/dragonBusinessDistrict/removeDragonBusinessDistrict"
        case .getUnionNewsList:
            return "api/dragonBusinessDistrict/pageBusinessDistrictInfo"
        case .updateAddress:
            return "api/address/updateDeliveryAddress"
        case .releaseUnionNews:
            return "api/dragonBusinessDistrict/saveBusinessDistrictInfo"
        case .getBusinessNewsList:
            return "api/businessNewsFlash/pageBusinessNewsFlash"
        case .getBusinessNewsType:
            return "api/masterType/listBusinessNewsFlashType"
        case .releaseBusinessNews:
            return "api/businessNewsFlash/saveBusinessNewsFlash"
        case .getDragonUnionUserNums:
            return "api/dragonBusinessDistrict/countOfDragonBusinessDistrictUser"
        case .getDragonKanbanType:
            return "api/masterType/listDragonKanbanBusinessType"
        case .sendDragonUnionChatMessage:
            return "api/dragonBusinessDistrict/saveDragonBusinessDistrictPrivateChat"
        case .getShopCartList:
            return "api/cart/listCartGoods"
        case .uploadImage:
            return "api/file/uploadImages"
        case .uploadVideo:
            return "api/file/uploadVideo"
        case .getGoodsType:
            return "api/goods/listGoodsCategory"
        case .getGoodsList:
            return "api/goods/pageGoods"
        case .getOrderList:
            return "api/order/pageOrderByStatus"
        case .getGoodsDetail:
            return "api/goods/selectGoodsDetail"
        case .getGoodsSpecification:
            return "api/goods/listGoodsSpecification"
        case .getGoodsSku:
            return "api/goods/listGoodsSku"
        case .addShopcart:
            return "api/cart/addGoodsToCart"
        case .removeGoodsFromShopcart:
            return "api/cart/removeGoodsFromCart"
        case .modifyShopcartGoodsCount:
            return "api/cart/modifyGoodsCount"
        case .preSaveOrder:
            return "api/order/preSaveOrder"
        case .listUserBusinessType:
            return "api/dragonBusinessDistrict/listUserBusinessType"
        case .saveUserBusinessType:
            return "api/dragonBusinessDistrict/saveUserBusinessType"
        case .privateMessageList:
            return "api/dragonBusinessDistrict/pageDragonBusinessDistrictPrivateChat"
        case .saveOrder:
            return "api/order/saveOrder"
        case .getReleaseNewsRecord:
            return "api/dragonBusinessDistrict/pageMyBusinessDistrictInfoHistory"
        case .getMyBusinessNewsRecordList:
            return "api/businessNewsFlash/pageMyBusinessNewsFlash"
        case .downloadImage:
            return "api/file/downloadImage"
        case .getOrderDetailInfo:
            return "api/order/selectOrderDetail"
        case .cancelOrder:
            return "api/order/cancelOrder"
        case .doOrderPay:
            return "api/payment/doOrderPay"
        case .confirmOrder:
            return "api/order/confirmOrder"
        case .fetchUserRecommendCode:
            return "api/userCenter/fetchUserRecommendCode"
        case .fetchOrderCount:
            return "api/userCenter/fetchOrderCount"
        case .pageUserPromotionCommission:
            return "api/userCenter/pageUserPromotionCommission"
        case .fetchUserBalance:
            return "api/userCenter/fetchBalance"
        case .pageRealNameIdentificationInfo:
            return "api/realNameIdentification/pageRealNameIdentificationInfo"
        case .saveRealNameIdentificationInfo:
            return "api/realNameIdentification/saveRealNameIdentificationInfo"
        case .deleteRealNameInfo:
            return "api/realNameIdentification/deleteRealNameInfo"
        case .getWechatPayPayment:
            return "api/payment/getWechatPayPayment"
        case .getAlipayPayInfoStr:
            return "api/payment/getAlipayPayInfoStr"
        case .bindPayAccountByUserId:
            return "api/userCenter/bindPayAccountByUserId"
        case .getCashOutPageInfo:
            return "api/userCenter/getCashOutPageInfo"
        case .updateUserRealNameById:
            return "api/userCenter/updateUserRealNameById"
        case .userCashOut:
            return "api/userCenter/userCashOut"
        case .changeHeaderImg:
            return "api/userCenter/changeHeaderImg"
        case .getUserInfo:
            return "api/userCenter/getUserInfo"
            
            
            
            
            
        case .passwordLogin:
            return "longShop/dt/admin/loginByOnlineSignxlb"
        case .lsqListInfo:
            return "longShop/xlb/lsquserlist"
        case .cityShareList:
            return "longShop/longtt/memsales/xlbproductshelflist"
        
//        case .uploadImg:
//            return "longweb/appFileCtl/fileUpload"
//        case .uploadVideo:
//            return "longweb/appFileCtl/fileUpload"
        case .goodslistcross:
            return "longweb/dt/suppler/goodslistcross"
        case .getcrossaddgcate:
            return "longShop/longtt/supp/getcrossaddgcate"
        
        case .lsqdele:
            return "longShop/xlb/lsqdele"
        case .userOrderList:
            return "longweb/dt/appOrder/getUserOrderCross"
        case .goodsDetail:
            return "longweb/dt/suppler/getsuppgoodsdetail4Cross"
        
        case .sendMessage:
            return "longweb/xlb/sendmessage"
        case .buyAtOnce:
            return "longweb/dt/appOrder/addOrderBuyNowCross"
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .getAlipayUserInfo:
            return .post
        case .getWechatUserInfo:
            return .post
        case .getWechatPayPayment:
            return .post
        case .getCountryCodeList:
            return .post
        case .passwordLogin, .telLogin:
            return .post
        case .releaseBoard, .changeNickname, .changeMobile:
            return .post
        case .getTotalRegister:
            return .post
        case .dragonUnionList:
            return .post
        case .getAddressList:
            return .post
        case .saveAddress:
            return .post
        case .deleteAddress:
            return .post
        case .deleteAccount:
            return .post
        case .removeDragonUnion:
            return .post
        case .getUnionNewsList:
            return .post
        case .updateAddress:
            return .post
        case .releaseUnionNews:
            return .post
        case .getBusinessNewsList:
            return .post
        case .getBusinessNewsType:
            return .post
        case .releaseBusinessNews:
            return .post
        case .getDragonUnionUserNums:
            return .post
        case .getDragonKanbanType:
            return .post
        case .sendDragonUnionChatMessage:
            return .post
        case .getShopCartList:
            return .post
        case .uploadImage:
            return .post
        case .uploadVideo:
            return .post
        case .getGoodsType:
            return .post
        case .getGoodsList:
            return .post
        case .getOrderList:
            return .post
        case .getGoodsDetail:
            return .post
        case .getGoodsSpecification:
            return .post
        case .getGoodsSku:
            return .post
        case .addShopcart:
            return .post
        case .removeGoodsFromShopcart:
            return .post
        case .modifyShopcartGoodsCount:
            return .post
        case .preSaveOrder:
            return .post
        case .listUserBusinessType:
            return .post
        case .saveUserBusinessType:
            return .post
        case .privateMessageList:
            return .post
        case .saveOrder:
            return .post
        case .getReleaseNewsRecord:
            return .post
        case .getMyBusinessNewsRecordList:
            return .post
        case .downloadImage:
            return .get
        case .getOrderDetailInfo:
            return .post
        case .cancelOrder:
            return .post
        case .doOrderPay:
            return .post
        case .confirmOrder:
            return .post
        case .fetchUserRecommendCode:
            return .post
        case .fetchOrderCount:
            return .post
        case .pageUserPromotionCommission:
            return .post
        case .fetchUserBalance:
            return .post
        case .pageRealNameIdentificationInfo:
            return .post
        case .saveRealNameIdentificationInfo:
            return .post
        case .deleteRealNameInfo:
            return .post
        case .getAlipayPayInfoStr:
            return .post
        case .bindPayAccountByUserId:
            return .post
        case .getCashOutPageInfo:
            return .post
        case .updateUserRealNameById:
            return .post
        case .userCashOut:
            return .post
        case .changeHeaderImg:
            return .post
        case .getUserInfo:
            return .post
            
            
            
            
            
        case .getVerificationCode:
            return .post
        case .bussiInfo:
            return .post
        case .lsqListInfo:
            return .post
        case .cityShareList:
            return .post
        case .addDragonUnion:
            return .post
//        case .uploadImg:
//            return .post
//        case .uploadVideo:
//            return .post
        case .goodslistcross:
            return .post
        case .getcrossaddgcate:
            return .post
        case .lsqdele:
            return .post
        case .userOrderList:
            return .post
        case .goodsDetail:
            return .post
//        case .getShopcartInfo:
//            return .post
       
        case .sendMessage:
            return .post
        case .buyAtOnce:
            return .post
        }
    }
    
    var task: Moya.Task {
        switch self {
        case .getAlipayUserInfo(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getWechatUserInfo(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getWechatPayPayment(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getCountryCodeList:
            return .requestParameters(parameters: [:], encoding: JSONEncoding.default)
        case .getTotalRegister(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .dragonUnionList(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getAddressList(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .passwordLogin(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .changeNickname(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .changeMobile(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .saveAddress(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .deleteAddress(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .deleteAccount(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .removeDragonUnion(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getUnionNewsList(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .updateAddress(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .releaseUnionNews(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getBusinessNewsList(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getBusinessNewsType(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .releaseBusinessNews(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getDragonUnionUserNums(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getDragonKanbanType(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default) 
        case .sendDragonUnionChatMessage(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getShopCartList(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getGoodsList(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getGoodsType(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getOrderList(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getGoodsDetail(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getGoodsSpecification(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getGoodsSku(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .addShopcart(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .removeGoodsFromShopcart(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .modifyShopcartGoodsCount(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .preSaveOrder(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .listUserBusinessType:
            return .requestParameters(parameters: [:], encoding: JSONEncoding.default)
        case .saveUserBusinessType(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .privateMessageList(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .saveOrder(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getReleaseNewsRecord(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getMyBusinessNewsRecordList(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .downloadImage(let params):
            return .requestParameters(parameters: params, encoding: URLEncoding.default)
        case .getOrderDetailInfo(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .cancelOrder(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .doOrderPay(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .confirmOrder(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .fetchUserRecommendCode, .fetchOrderCount, .getAlipayPayInfoStr:
            return .requestParameters(parameters: [:], encoding: JSONEncoding.default)
        case .pageUserPromotionCommission(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .fetchUserBalance(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .pageRealNameIdentificationInfo(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .saveRealNameIdentificationInfo(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .deleteRealNameInfo(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .bindPayAccountByUserId(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getCashOutPageInfo:
            return .requestParameters(parameters: [:], encoding: JSONEncoding.default)
        case .updateUserRealNameById(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .userCashOut(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .changeHeaderImg(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getUserInfo:
            return .requestParameters(parameters: [:], encoding: JSONEncoding.default)
            
        case .uploadImage(let params, let files,let name):
            var formDatas = [MultipartFormData]()
            for img in files {
                let imageData = img.jpegData(compressionQuality: 0.3)
                
//                printLog("data的大小:\(imageData?.count)")
                let imageName = JDTools.currentTimeStamp()+".jpg"
                let formData = MultipartFormData(provider: .data(imageData!), name: name, fileName: imageName, mimeType: "image/jpeg")
                formDatas.append(formData)
                
//                for key in params.keys {
//                    if let value = JSON(params[key] as Any).string {
//                        let paramsFormData = MultipartFormData(provider: .data(value.data(using: .utf8)!), name: key)
//                        formDatas.append(paramsFormData)
//                    }
//                }
                
            }
            return .uploadMultipart(formDatas)
        case .uploadVideo(let params, let videoUrl, let name):
            var formDatas = [MultipartFormData]()
            if let videData = try? Data(contentsOf: videoUrl, options: .alwaysMapped) {
                let formData = MultipartFormData(provider: .data(videData), name: name, fileName: ".mp4", mimeType: "video/mp4")
                formDatas.append(formData)
            }
//            for key in params.keys {
//                if let value = JSON(params[key] as Any).string {
//                    let paramsFormData = MultipartFormData(provider: .data(value.data(using: .utf8)!), name: key)
//                    formDatas.append(paramsFormData)
//                }
//            }
            
            return .uploadMultipart(formDatas)
            
            
            
            
            
            
            
            
            
            
        case .telLogin(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .releaseBoard(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getVerificationCode(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .bussiInfo(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .lsqListInfo(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .cityShareList(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .addDragonUnion(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .goodslistcross(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .getcrossaddgcate(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .lsqdele(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .userOrderList(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .goodsDetail(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
//        case .getShopcartInfo(let params):
//            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .sendMessage(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
        case .buyAtOnce(let params):
            return .requestParameters(parameters: params, encoding: JSONEncoding.default)
//        case .uploadImg(let params, let files,let name):
//            var formDatas = [MultipartFormData]()
//            for img in files {
//                let imageData = img.jpegData(compressionQuality: 0.3)
//                let imageName = JDTools.currentTimeStamp()+".jpg"
//                let formData = MultipartFormData(provider: .data(imageData!), name: name, fileName: imageName, mimeType: "image/jpeg")
//                formDatas.append(formData)
//                for key in params.keys {
//                    if let value = JSON(params[key] as Any).string {
//                        let paramsFormData = MultipartFormData(provider: .data(value.data(using: .utf8)!), name: key)
//                        formDatas.append(paramsFormData)
//                    }
//                }
//            }
//            printLog("上传文件参数:\(formDatas)")
//            return .uploadMultipart(formDatas)
//        case .uploadVideo(let params, let videoUrl, let name):
//            var formDatas = [MultipartFormData]()
//            if let videData = try? Data(contentsOf: videoUrl, options: .alwaysMapped) {
//                let formData = MultipartFormData(provider: .data(videData), name: name, fileName: ".mp4", mimeType: "video/mp4")
//                formDatas.append(formData)
//            }
//            for key in params.keys {
//                if let value = JSON(params[key] as Any).string {
//                    let paramsFormData = MultipartFormData(provider: .data(value.data(using: .utf8)!), name: key)
//                    formDatas.append(paramsFormData)
//                }
//            }
//
//            return .uploadMultipart(formDatas)
        }
    }
    
    var headers: [String : String]? {
        return [
            "Content-type" : "application/json",
            "Accept" : "application/json, text/plain, */*",
            "jdtoken": JDLoginModel.default.token ?? ""
//            "Authorization": "Basic aDVfYzpoNV9jX3NlY3JldA==",//String.init(format: "Basic %@", "ios_c:ios_c_secret".base64Encoding()),
//            "Tenant-Id": "000000"//,
    //        "Blade-Auth": ""//WJBTokenModel.default.sessionId ?? "" //WJBConfigManager.wjbConfigManager.userInfoDic.sessionId ?? "" //"bearer eyJ0eXAiOiJKc29uV2ViVG9rZW4iLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJpc3N1c2VyIiwiYXVkIjoiYXVkaWVuY2UiLCJ0ZW5hbnRfaWQiOiIwMDAwMDAiLCJyb2xlX25hbWUiOiJhZG1pbmlzdHJhdG9yLHVzZXIsaHIsbWFuYWdlcixib3NzIiwidXNlcl9pZCI6IjExMjM1OTg4MjE3Mzg2NzUyMDEiLCJyb2xlX2lkIjoiMTEyMzU5ODgxNjczODY3NTIwMSwxMTIzNTk4ODE2NzM4Njc1MjAyLDExMjM1OTg4MTY3Mzg2NzUyMDMsMTEyMzU5ODgxNjczODY3NTIwNCwxMTIzNTk4ODE2NzM4Njc1MjA1IiwidXNlcl9uYW1lIjoiYWRtaW4iLCJuaWNrX25hbWUiOiLnrqHnkIblkZgiLCJ0b2tlbl90eXBlIjoiYWNjZXNzX3Rva2VuIiwiZGVwdF9pZCI6IjExMjM1OTg4MTM3Mzg2NzUyMDEiLCJhY2NvdW50IjoiYWRtaW4iLCJjbGllbnRfaWQiOiJzYWJlciIsImV4cCI6MTkwMjc5MzExMCwibmJmIjoxNTg3NDMzMTEwfQ.7mO1mV6Q0jN7MVTR26zFHzI_a_apTyf9-ie6V-u-E4M"
        ]
    }
    
    
}

func jsonToData(jsonDic:Dictionary<String, Any>) -> Data? {
    if (!JSONSerialization.isValidJSONObject(jsonDic)) {
        print("is not a valid json object")
        return nil
    }
    //利用自带的json库转换成Data
    //如果设置options为JSONSerialization.WritingOptions.prettyPrinted，则打印格式更好阅读
    let data = try? JSONSerialization.data(withJSONObject: jsonDic, options: [])
    //Data转换成String打印输出
    let str = String(data:data!, encoding: String.Encoding.utf8)
    //输出json字符串
    print("Json Str:\(str!)")
    return data
}
